jQuery(function($) {
//	$.datepicker.regional['zh-CN'] ;
	
	$('input[type="checkbox"]').each(function(i,el){
		$(el).on('click',function(){
			alert("1");
		});
		
	});
	
	var grid_selector = "#grid-table";
	var pager_selector = "#grid-pager";
									
	var parent_column = $(grid_selector).closest('[class*="col-"]');
	//对话框标题
		$.widget("ui.dialog", $.extend({}, $.ui.dialog.prototype, {
			_title: function(title) {
				var $title = this.options.title || '&nbsp;'
				if( ("title_html" in this.options) && this.options.title_html == true )
					title.html($title);
				else title.text($title);
			}
		}));
	//resize to fit page size
	$(window).on('resize.jqGrid', function () {
	    $(grid_selector).jqGrid( 'setGridWidth', parent_column.width() );
	})
	
	jQuery(grid_selector).jqGrid({
			//direction: "rtl",
			ajaxGridOptions: { contentType: 'application/json; charset=UTF-8' },
			url: ctx + '/epay/alipaybusinessinfo/list',
			datatype : "json",   
			height : 270,
			colNames : ['应用', '账号名称', '分账比例', '支付宝账号', '收款人', '是否启用', '操作' ],
			colModel : [
			{
				name : 'loginName',
				index : 'loginName',   
				width : 130,
				sortable :false,
				editable : true
			}
			 , {
				name : 'alipayAccount',
				index : 'alipayAccount',   
				width : 130,
				sortable :false,
				editable : true
			}
			 , {
				name : 'SplitRatio',
				index : 'SplitRatio',
				width : 150,
				sortable : false,
				editable : true
			}
			 , {
				name : 'alipayAccount',
				index : 'alipayAccount',
				width : 120,
				sortable : false,
				editable : true
			}
			, {
				name : 'payeeName',
				index : 'payeeName',
				width : 120,
				sortable : false,
				editable : true
			}
			, {
				name : 'isEnable',
				index : 'isEnable',
				width : 120,
				sortable : false,
				editable : true
			}
			, {
				name : 'oper',
				index : 'oper',
				width : 80,
				fixed : true,
				sortable : false,
			} ],

			viewrecords : true,
			rowNum : 15,
			//rowList:[10,20,30],
			pager : pager_selector,
			onPaging : function(first, last, prev, next) {
				
			},
			altRows : true,
			//toppager: true,
			multiselect : true,
			//multikey: "ctrlKey",
			multiboxonly : true,

			loadComplete : function() {
				var table = this;
				setTimeout(function() {
					updatePagerIcons(table);
					enableTooltips(table);
				}, 0);
			},
			gridComplete : function() {
				
				var ids = jQuery("#grid-table").jqGrid('getDataIDs');
				for (var i = 0; i < ids.length; i++) {
					var id = ids[i];
					var rowData = $("#grid-table").getRowData(id);
					var editBtn ="<a href='#' style='color:#f60' onclick='view(\""
							+ id + "\")' >编辑</a>";

					jQuery("#grid-table").jqGrid('setRowData', ids[i], {oper : editBtn});
				}

			},
			// 读取返回的数据格式
			jsonReader : {
				repeatitems : true,
				root : "results.results", // 返回的具体的数据的数组
				row : "results.size", // 返回的行数
				//page:"pageCurrNum", // 当前的页数
				total : "results.maxPage", // 返回的总页数 
				records : "results.size", // 返回的总记录条数 
				repeatitems : true,
			    // id: "tsortMark"
			},

			editurl : "/dummy.html",
			caption : ""

	});
	$(window).triggerHandler('resize.jqGrid');//trigger window resize to make the grid get the correct size

	//replace icons with FontAwesome icons like above
	function updatePagerIcons(table) {
		var replacement = {
			'ui-icon-seek-first' : 'ace-icon fa fa-angle-double-left bigger-140',
			'ui-icon-seek-prev' : 'ace-icon fa fa-angle-left bigger-140',
			'ui-icon-seek-next' : 'ace-icon fa fa-angle-right bigger-140',
			'ui-icon-seek-end' : 'ace-icon fa fa-angle-double-right bigger-140'
		};
		$('.ui-pg-table:not(.navtable) > tbody > tr > .ui-pg-button > .ui-icon').each(
				function() {
					var icon = $(this);
					var $class = $.trim(icon.attr('class').replace('ui-icon', ''));
					if ($class in replacement)icon.attr('class', 'ui-icon '
								+ replacement[$class]);
				})
	}

	function enableTooltips(table) {
		$('.navtable .ui-pg-button').tooltip({
			container : 'body'
		});
		$(table).find('.ui-pg-div').tooltip({
			container : 'body'
		});
	}
	//var selr = jQuery(grid_selector).jqGrid('getGridParam','selrow');
});



function searchT(){
 	var clueCode=$("#loginName").val();
	var campaignDesc=$("#SplitRatio").val();
	var name=$("#alipayAccount").val();
	var mobilePhone=$("#payeeName").val();
	var dlrCode=$("#isEnable").val();
	var smartCode=$("#alipayAccount").val();
	 
	$("#grid-table").jqGrid('setGridParam',{ 
	url:ctx + "/epay/alipaybusinessinfo/list",  
	postData:{'loginName':loginName, 'SplitRatio':SplitRatio,'alipayAccount':alipayAccount,'payeeName':payeeName,'isEnable':isEnable,'alipayAccount':alipayAccount}, //发送数据  
    page:1
    }).trigger("reloadGrid"); //重新载入 
	/* } else{
		$("#grid-table").jqGrid('setGridParam',{ 
            url:"${ctx}/api/dbinterface/list", 
            page:1
        }).trigger("reloadGrid"); //重新载入 
    } */
}


